
$(function (){
	$("#names").val($("#state").val());
	$("#morning").val($("#mornings").val());
	let competitionType = location.href.split('?')[1].split('=');

	let objectDate = {
		'moduleType':2,
		'competitionType': competitionType[3]
	};

	$.ajax({
		cache : true,
		type : "POST",
		url:'/jz-jinzhuan-disposition-module/getModuleList',
		data : JSON.stringify(objectDate),// 你的formid
		async : false,
		headers: {
			'Content-Type':'application/json;charset=UTF-8'
		},
		error : function(request) {
			parent.layer.alert("Connection error");
		},

		success : function(data) {
			let str = '', srr = '';
			let moduleId = $("#moduleName").val();
			if (data.code == 0) {
				sessionStorage.setItem('vs',JSON.stringify(data.data));
				$.each(data.data,function (k,v){
					if( k == 0 ){
						str += `<option value="">请选择</option>`;
					}

					if( moduleId == v.moduleName ){
						str += `<option value="${v.id}" selected>${v.moduleName}</option>`;
						v.dispositionTopic.map(function (v){
							srr += `<li><span>任务名称:${v.topicName}</span>  <span>任务分数:${v.score}</span></li>`
						})
					}else{
						str += `<option value="${v.id}">${v.moduleName}</option>`;
					}

				})

				$("#templet").html(str);
				$("#templetScore").html(srr);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	})

	$('body').on('change','#templet',function (ev){
		let vs = JSON.parse(sessionStorage.getItem('vs'));
		let exam = $(this).find("option:selected").index();
		let sar = '';
		if( exam - 1 < 0 ){
			$("#templetScore").html('');
		}else{
			vs = vs[exam-1];
		}

		if( $(this).find("option:selected").val() == vs.id ){

			vs.dispositionTopic.map(function (v){
				sar += `<li><span>任务名称:${v.topicName}</span>  <span>任务分数:${v.score}</span></li>`
			})
			$("#templetScore").html(sar);

		}

	})

})

layui.use(['laydate','xmSelect'],function (){
	var laydate = layui.laydate;
	var xmSelect = layui.xmSelect;

	laydate.render({
		elem: '#startTime'
		,type: 'datetime'
	});
	laydate.render({
		elem: '#endTime'
		,type: 'datetime'
	});

})

function save() {
	// validateRule();

	if (!$("#name").val()) {
		layer.msg('请选择考场')
		return false;
	}

	if (!$("#startTime").val()) {
		layer.msg('请选择考试开始时间')
		return false;
	}

	if (!$("#endTime").val()) {
		layer.msg('请选择考试结束时间')
		return false;
	}

	$.ajax({
		cache: true,
		type: "POST",
		url: "/jzweb/examinationBatchCom/updates",
		data: $('#signupForm').serialize(),// 你的formid
		async: false,
		error: function (request) {
			parent.layer.alert("Connection error");
		},
		success: function (data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
}